<?php

use wechat\assets\WechatAsset;
use wechat\models\WeConfig;
use yii\web\View;

/**
 * @var View $this
 */

$this->title = '微信配置列表';
$data = WeConfig::find()->select(['id', 'title', 'appid', 'debug', 'status', 'type', 'is_default'])->asArray()->all();
$model = new WeConfig();
// AdminAsset
$imagesDir = WechatAsset::register($this)->baseUrl;
?>
<div ng-controller="configIndexCtrl">
    <div class="xblock">
        <button class="layui-btn layui-btn-xs" ng-click="toEdit(0)">
            <i class="icon iconfont layui-extend-add"></i> 添加配置
        </button>
        <span class="x-right">共有数据：<span><span ng-bind="pagination.itemsCount">0</span> 条</span>
    </div>

    <table class="layui-table">
        <tr>
            <th>ID</th>
            <th><?php echo $model->getAttributeLabel('type') ?></th>
            <th><?php echo $model->getAttributeLabel('title') ?></th>
            <th><?php echo $model->getAttributeLabel('appid') ?></th>
            <th style="width: 60px;"><?php echo $model->getAttributeLabel('debug') ?></th>
            <th style="width: 40px;"><?php echo $model->getAttributeLabel('status') ?></th>
            <th style="width: 60px;"><?php echo $model->getAttributeLabel('is_default') ?></th>
            <th>操作</th>
        </tr>

            <tr ng-repeat="x in datas">
                <td><span ng-bind="x.id"></span></td>
                <td><span ng-bind="x.type_text"></span></td>
                <td><span ng-bind="x.title"></span></td>
                <td><span ng-bind="x.appid"></span></td>

                <td>
                    <button
                            ng-click="toggleAttr('debug', x)"
                            class="layui-btn layui-btn-xs"
                            ng-class="{'layui-btn-normal':x.debug == 1, 'layui-btn-primary':x.debug == 0}"
                            ng-bind="x.debug_text"></button>

                </td>
                <td>
                    <button
                            ng-click="toggleAttr('status', x)"
                            class="layui-btn layui-btn-xs"
                            ng-class="{'layui-btn-normal':x.status == 1, 'layui-btn-primary':x.status == 0}"
                            ng-bind="x.status_text"></button>
                </td>
                <td>
                    <button
                            ng-click="toggleAttr('is_default', x)"
                            class="layui-btn layui-btn-xs"
                            ng-class="{'layui-btn-normal':x.is_default == 1, 'layui-btn-primary':x.is_default == 0}"
                            ng-bind="x.is_default_text"></button>
                </td>
                <td>
                    <button
                       ng-click="showConfig(x)"
                       title="查看"
                       class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon">&#xe63c;</i></button>
                    <button
                       ng-click="toEdit(x)"
                       title="编辑"
                       class="layui-btn layui-btn-sm layui-btn-warm"><i class="layui-icon">&#xe642;</i></button>
                    <button
                       ng-click="toDelete(x)"
                       title="删除"
                       class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
                </td>
            </tr>

    </table>
</div>
<div>
    <div>注意：确保你的公众号配置为"已启用"，才是真正的启用</div>
    <img src="<?php echo $imagesDir ?>/images/wechat.1.png" style="width: 50%;">
</div>
<input name="_csrf" type="hidden" id="_csrf" value="<?= \Yii::$app->request->csrfToken ?>">
